{extend name='public/content'}

{block name="title"}
	退货
{/block}

{block name="body"}

<div class="layui-container" ng-app="myApp" ng-controller="myCtrl">  
		  <div class="layui-row" >
		    <div class="layui-col-xs6 layui-col-sm6 layui-col-md4">
		    	名称	{{x.good.name}}
		    </div>
		     <div class="layui-col-xs6 layui-col-sm6 layui-col-md4">
		    	名称	{{x.spec_detail}}
		    </div>
		    <div class="layui-col-xs6 layui-col-sm6 layui-col-md4">
		    	<img style="width: 100px;height: 100px" ng-src="{{x.good.logo}}" alt="">
		    </div>
		    <div class="layui-col-xs4 layui-col-sm12 layui-col-md4">
		     	{{x.good.description}}
		    </div>
		    <div class="layui-col-xs4 layui-col-sm7 layui-col-md8">
		    	数量{{x.goods_num}}
		    </div>
		    <div class="layui-col-xs4 layui-col-sm5 layui-col-md4">
		   	   总价{{x.signal_price}} 
		    </div>
		  </div>
		

		<div class="layui-row" >
		    <div class="layui-col-xs6 layui-col-sm6 layui-col-md2">
		    	退款原因
		    	<input ng-model="resion" ng-init="resion=''">
		    </div>
		     <div class="layui-col-xs6 layui-col-sm6 layui-col-md2">
		    	退款数量
		    	<input ng-model="sum" type="num" ng-init="sum='0'">
		    </div>
		    <div class="layui-col-xs6 layui-col-sm6 layui-col-md8">
		    	退款金额
		    	{{sum*x.spec_signal_price}}
		    </div>
		  </div>
			<div style="position:relative">
			    <div class="uploadimage"><input type="hidden" name="file_1" ng-model="image" ng-init="image=''"></div>
			    <a data-file="one" data-field="file_1" data-type="png,jpg" data-uptype="local" href="javascript:void(0)" class="uploadbutton">上传图片</a>
			</div>

		<div class="layui-row" >
		    <div ng-click="feedbadk(x)" class="layui-col-xs6 layui-col-sm6 layui-col-md4 layui-btn layui-btn-sm layui-btn-normal">
		    	点击 退款
		    </div>
		</div>
</div>	

{/block}

{block name="script"}
	<script type="text/javascript">
		require(['jquery','angular'], function () { 
			var app = angular.module('myApp', []);
			app.controller('myCtrl', function($scope, $http) {
				  $scope.x={};
				  $http({
				        method: 'GET',
				        url: "{:url('index/order/goodbackorderdertailapi')}?id={$id}"
				    }).then(function successCallback(response) {
				        $scope.x = response.data;     
				    })
				    $scope.$watch('sum',  function(newValue, oldValue) {
			            if (newValue>parseInt($scope.x.goods_num)) { 
			            	console.dir(newValue+"----"+oldValue);
			            	$scope.sum=0;
			            } 
			        });
				  $scope.feedbadk=function(x){
				  	var reson = $scope.resion
				  	var sum = $scope.sum;
				  	var image = $scope.image;
				  	if(sum==parseInt($scope.x.goods_num)){
				  		var type=2
				  	}else{
				  		var type=1;
				  	}
				  	if(sum==0){
				  		return;
				  	}
				  	if(reson==''){
				  		return;
				  	}
				  	var data ={
				  		reason:reson,
				  		sum:sum,
				  		image:image,
				  		id:x.id,
				  		type:type,
				  		amount:sum*$scope.x.spec_signal_price,
				  		goodsid:$scope.x.goods_id
				  	}
				  	$http.post("{:url('index/order/fadeback')}",data)
				  	.then(function(res){
				  		console.dir(res.status);
				  		if(res.data.status=="0"){
				  			alert(res.data.msg);
				  		}
				  		if(res.data.status=="1"){
				  			alert(res.data.msg);
				  		}
				  	});
				  	   // $http({
					   //      method: 'GET',
					   //      url: "{:url('index/order/fadeback')}"
					   //  }).then(function successCallback(response) {
					   //      $scope.x = response.data;
					   //      console.log(response.data) 
					   //  })
				  }

				   $('[name="file_1"]').on('change', function () {
				        $(this).parent().attr('data-tips-image', this.value).css('backgroundImage', 'url(' + this.value + ')');
				  		$scope.$apply(function() {   
			            	$scope.image = $('[name="file_1"]').val();   
			            });
				   });
			})



		})
	</script>
 	
{/block}
	
{block name="style"}
 <style type="text/css">
 	
 </style>
{/block}
